import React from 'react'
// 状态不可变:不能直接修改state中的原值
export default class App extends React.Component {
  state = {
    count: 10,
    list: [1, 2, 3],
  }
  handleClick() {
    // 修改state中的值:setState
    //  正确的示范
    this.setState({
      count: this.state.count + 1,
    })
    this.setState({
      list: [...this.state.list, 4],
    })

    //  错误示范：
    // this.state.count += 1
    // this.state.count++
    // this.setState({
    //   count: this.state.count++,
    //   count: ++this.state.count,
    // })
    // this.state.list.push(4)
  }
  render() {
    return (
      <>
        <h2>计时器：{this.state.count}</h2>
        <button
          onClick={() => {
            this.handleClick()
          }}
        >
          点击我+1
        </button>
      </>
    )
  }
}
